package com.study.example.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by User on 2017/9/14.
 */
@RestController
public class RedisShareSessionController {

    @RequestMapping("getSessionId")
    public String getSessionId(HttpServletRequest request) {
        // 以不同的端口启动服务，分别请求此接口
        String sessionId = request.getSession().getId();
        Object user_info = request.getSession().getAttribute("user_info");
        if (user_info == null) {
            System.out.println("第一个请求登陆账号之后，生成user_info");
            user_info = "zql登陆了";
            request.getSession().setAttribute("user_info", user_info);
        } else {
            System.out.println("session 已经存在user_info了  user_info:" + user_info);
        }

        return sessionId + "-->" + user_info;


    }

}
